Skip to content

Comments

Remove UsageFunc dispatch from DefaultUsage to fix infinite recursion#16

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/resolve-issue-15-options
Closed

Remove UsageFunc dispatch from DefaultUsage to fix infinite recursion#16
Copilot wants to merge 2 commits intomainfrom
copilot/resolve-issue-15-options

Conversation

Copy link

Copilot AI commented Feb 19, 2026

DefaultUsage checks UsageFunc and calls it if set, making it impossible to call DefaultUsage from within a UsageFunc without infinite recursion. The function name implies "give me the default behavior" but instead re-dispatches to custom logic.

Changes

  • usage.go: Remove the UsageFunc guard from DefaultUsage so it always produces default output
  • run.go: Move UsageFunc dispatch to ParseAndRun — check UsageFunc first on help, fall back to DefaultUsage

This makes DefaultUsage composable:

cmd.UsageFunc = func(c *cli.Command) string {
    return cli.DefaultUsage(c) + "\n\nExamples:\n  myapp --verbose"
}

Previously required a workaround of nilling out UsageFunc before calling DefaultUsage.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…recursion (#15)

DefaultUsage now always produces the default output, making it composable
from within a UsageFunc. The UsageFunc dispatch is moved to ParseAndRun.

Co-authored-by: mfridman <6278244+mfridman@users.noreply.github.com>
Copilot AI changed the title [WIP] Discuss options to resolve issue 15 Remove UsageFunc dispatch from DefaultUsage to fix infinite recursion Feb 19, 2026
Copilot AI requested a review from mfridman February 19, 2026 14:04
@mfridman mfridman closed this Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants